package com.leetcode.LeetCode精选TOP面试题;

/**
 * @author 覃国强
 * @date 2022-07-06 17:31
 */
public class 题库_0191_位1的个数 {

  static
  public class Solution {
    // you need to treat n as an unsigned value
    public int hammingWeight(int n) {
      int answer = 0;
      while (n != 0) {
        answer += (n & 1);
        n >>>= 1;
      }
      return answer;
    }
  }

}
